module cl {
	export class SeeAction extends ActionPerformer {
		constructor(force : number, range : number = 1) {
			super();
			this.type = 1;
			this.paramKeys = JSON.stringify(["force", "range"]);
			this.paramVals = JSON.stringify([force, range]);
		}

		public accept() : void {
			let troop = Campaign.troop[this.troopid];

			let vals = JSON.parse(this.paramVals);
			let force = vals[0] as number;
			let range = vals[1] as number;

			if (range == 0) {
				ForceMapUtil.refreshTile(Campaign.force[force].force_map, Campaign.zone, this.tid);
			} else if (range == 1) {
				ForceMapUtil.refreshTileAndNeighbor(Campaign.force[force].force_map, Campaign.zone, this.tid);
			} else {
				let payMap = Map.routeEngine.payMap(Util.createArray(Map.tileEngine.tileCount, 1), this.tid, 2 * range).payMap;
				for (let i = 0; i < payMap.length; i++) {
					if (payMap[i] >= 0 && payMap[i] <= 2 * range) {
						ForceMapUtil.refreshTile(troop.force_map, Campaign.zone, i);
					}
				}
			}
		}

		public acceptOnce() : void { this.accept(); }

		public duration() : number {
			return 1;
		}

		public play(map : CampaignPage) : void {
			let vals = JSON.parse(this.paramVals);
			let force = vals[0] as number;
			let range = vals[1] as number;

			if (force != Campaign.time_ref.force_of_step){
				return;
			}

			let payMap = Map.routeEngine.payMap(Util.createArray(Map.tileEngine.tileCount, 1), this.tid, 2 * range).payMap;
			for (let i = 0; i < payMap.length; i++) {
				if (payMap[i] >= 0 && payMap[i] <= 2 * range) {
					let mistImage = map.groupMist.getChildByName(String(i));
					if (mistImage != null){
						map.groupMist.removeChild(mistImage);
					}
				}
			}
		}
	}
}